/*
 * Main.java
 *
 *  created: 19.8.2011
 *  charset: UTF-8
 *  license: MIT (X11) (See LICENSE file for full license)
 */
package cz.mp.k3bg;

import cz.mp.k3bg.gui.Dialogs;
import cz.mp.k3bg.gui.MainFrame;
import cz.mp.k3bg.log.LoggerManager;
import cz.mp.util.Stopwatch;
import java.awt.SplashScreen;
import java.util.logging.Logger;
import javax.swing.UIManager;

// TODO + undo/redo pro textová pole
// TODO + prompt s nápovědou nebo formátem některých textových polí

// TODO +(?) správa projektu (možnost načíst a uložit projekt) -- používat soubor OPF jako soubor projektu (?)

// TODO ^ unit testy balíku .core
// TODO ^?? pro logování použít log4j ??

// TODO + TocFilesParser + použití;  (možnost vybrat ToC jen z pracovního adresáře, testovat, zda soubory existují)

// TODO ^? balík .gui.component a .gui.helper a .gui.plaf do extra projektu, 

// (pozn. viz  javadoc v  cz.mp.k3bg.core.packageinfo.java  --  info jak použít)

/**
 *
 * @author Martin Pokorný
 * @version 0.1
 */
public class Main {

    private static final boolean DEBUG = false;
    private static final Logger logger =
            LoggerManager.getLogger(Main.class, DEBUG);

    /** */
    private static SplashScreen splash = null;


    /** */
    private static void initLaFBase() {
        UIManager.put("swing.boldMetal", false);
        UIManager.put("swing.aatext", true);       
    }

    /** */
    private static void initLaF4Debug() {
        if (!DEBUG) {
            return;
        }
        
		try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
//            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            // --- pokus  jgoodies look
//            UIManager.setLookAndFeel("com.jgoodies.looks.windows.WindowsLookAndFeel");
//            UIManager.setLookAndFeel("com.jgoodies.looks.plastic.Plastic3DLookAndFeel");
//            UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticLookAndFeel");
//            UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
            // --- 
        }
		catch (Exception ex) {
			// nic
		}
    }

    /**
     * 
     */
    private static void showGui() {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                splash = SplashScreen.getSplashScreen();

                if (splash == null) {
                    logger.warning("SplashScreen.getSplashScreen() --> null");
                }  
                
                Stopwatch startupTime = new Stopwatch();
                startupTime.start();

                MainFrame.getInstance().setVisible(true);

                startupTime.stop();

                logger.config("startup in  " +
                        startupTime.getTimeSec() + " s");
                
                if (splash != null && splash.isVisible()) {
                    splash.close();
                }                  
            }
        });        
    }


    // -------------------------------------------------------------------------
    /** */
    public static void main(String[] args) throws Exception {
        try {
            Application.logConfigInfo();

            initLaFBase();            
            initLaF4Debug();
            
            logger.config("LaF name = " + UIManager.getLookAndFeel().getName());

            showGui();
            
        } catch (Exception ex) {
            logger.severe(ex.toString());
            Dialogs.showErrorDialog(ex.toString());
            throw ex;
        }
    }
}   // Main
